package com.yoda.youdianda.vo;

import com.yoda.youdianda.domain.YddArticle;
import com.yoda.youdianda.domain.YddCate;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Objects;

/**
 * @author shawn
 * @date 2022年 11月 13日 11:36
 * 文章分类数vo
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class YddCateVo {
    private int id;

    private String catename; //获取分类文章数

    private int num;

    /*vo快速初始化*/
    public static YddCateVo init(YddCate cate, List<YddArticle> articles) {
        YddCateVo vo = new YddCateVo();
        vo.setId(cate.getId());
        vo.setCatename(cate.getCatename());
        int num = 0;
        for (YddArticle article : articles) {
            if (!Objects.isNull(article.getCateid()) && Objects.equals(article.getCateid(), cate.getId())) {
                num++;
            }
        }
        vo.setNum(num);
        return vo;
    }
}